c语言多级菜单 您所在的位置:网站首页 c语言typedef struct的意思 c语言多级菜单

c语言多级菜单

2022-12-16 16:56| 来源: 网络整理| 查看: 265

//多级菜单 #include //定义结构体 typedef struct{ unsigned char current; unsigned char up;//上键 unsigned char down;//下键 unsigned char enter; //确认键 void (*current_operation)();//函数指针 }key_table;

//菜单1 void fun1() { printf(“清华北大\n”); } //菜单2 void fun2() { printf(“海南师范\n”); } //菜单3 void fun3() { printf(“海洋热带\n”); }

//定义菜单组合数组 key_table table[7]={ {0,2,1,0,(*fun1)}, {1,0,2,0,(*fun2)}, {2,1,0,0,(*fun3)} }; char Key=0;//按键缓存unsigned char func_index=0;//菜单页void (*current_operation_index)();//定义指针变量int main(){ Key=0; current_operation_index=table[func_index].current_operation; //获取函数菜单地址 (*current_operation_index)();//执行当函数 while(1) { Key=0;//按键清零 Key=getchar();//获取按键输入 if(Key==‘2’) { func_index=table[func_index].up; //向上翻 current_operation_index=table[func_index].current_operation; //获取函数菜单地址 Key=0; //按键清零 (*current_operation_index)();//执行当函数 } if(Key==‘8’) { func_index=table[func_index].down; //向下翻 current_operation_index=table[func_index].current_operation;//获取函数菜单地址 Key=0;//按键清零 (*current_operation_index)();//执行当函数 } } }



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有